/*
 * @Author: liuxinyea
 * @Date: 2024-08-11 20:52:04
 * @LastEditors: liuxinyea
 * @LastEditTime: 2024-08-11 21:25:09
 * @Description: 描述
 */
import { _decorator, Component, EventMouse, Input, Node } from 'cc';
import { MouseManager } from './manager/MouseManager';
const { ccclass, property } = _decorator;

@ccclass('Cell')
export class Cell extends Component {
    public currentPlant: Node;
    protected onLoad(): void {
        this.node.on(Input.EventType.MOUSE_DOWN,this.onMouseDown,this);
        this.node.on(Input.EventType.MOUSE_MOVE,this.onMouseMove,this);
    }
    protected onDestroy(): void {
        this.node.off(Input.EventType.MOUSE_DOWN, this.onMouseDown, this);
        this.node.off(Input.EventType.MOUSE_MOVE, this.onMouseMove, this);
    }
    onMouseDown(event:EventMouse) {
        MouseManager.instance.placePlant(this);
    }
    onMouseMove(event: EventMouse){
       MouseManager.instance.onMouseMove(event);
    }
    addPlant(plant:Node):boolean{
        if(this.currentPlant){
            return false
        }
        this.currentPlant = plant;
        this.currentPlant.setPosition(this.node.position);
        return true
    }
}

